<?php
require(dirname(__FILE__).'/inc/config.inc.php');
require(dirname(__FILE__).'/inc/smarty/Smarty.class.php');
require(ADMIN_ROOT.'../include/func.class.php');
require(ADMIN_ROOT.'../include/syspage.class.php');
/*
 **************************
 (C)2010-2013 aircms
 update: 2013-05-22
 person: selenium
 **************************
 */

//初始化参数
$tbname = '#@__admin';
$gourl  = 'admin.php';
$action = isset($action) ? $action : '';
$is_htmldir = $cfg_is_htmldir;
$default_htmldir = 'en';
$htm_ext = '.html';

//======================samrty配置区===============================
$smarty = new Smarty;
$smarty->setTemplateDir(ADMIN_ROOT.'../templates/templates');
$smarty->setCompileDir(ADMIN_ROOT.'../templates/templates_c');
$smarty->setConfigDir(dirname(__FILE__).'/inc/smarty/configs');
$smarty->setCacheDir(dirname(__FILE__).'/inc/smarty/cache');
$smarty->left_delimiter = "{#";
$smarty->right_delimiter = "#}";
$smarty->force_compile = false;//强迫编译
$smarty->debugging = false;  //调试
$smarty->caching = false; //开启缓存
$smarty->cache_lifetime = 120; //缓存存活时间（秒）
//=========================samrty配置区===========================
if($is_htmldir=='Y')//判断启用英文目录
{
	if(!file_exists(PHPMYWIND_ROOT.'/'.$default_htmldir.'/'))
	{
		//创建目录
		mkdirs(PHPMYWIND_ROOT.'/'.$default_htmldir.'/');
		//移动资源文件夹
		dir_copy(PHPMYWIND_ROOT.'/templates/default/',PHPMYWIND_ROOT.'/'.$default_htmldir.'/templates/default/');
	}
}
if($action=='do')
{
	ignore_user_abort(true);
    set_time_limit(0);
	create_index();
	create_index('en');
	create_all();
	create_all('en');
	echo '处理完成！';
}
function create_all($lang='cn')
{
	$data = array();
	$all_class = get_all_infoclass($lang);
	if(!empty($all_class))
	{
		$page_tem = array();
		$article_tem = array();
		$imginfo_tem = array();
		$download_tem = array();
		$goods_tem = array();
		foreach ($all_class as $k=>$v)
		{
			if($v['infotype']=='0')//单页处理
			{
				$page_tem[] = $v;
			}
			elseif($v['infotype']=='1')//列表文章
			{
				$article_tem[] = $v;
			}
			elseif($v['infotype']=='2')//图片类型
			{
				$imginfo_tem[] = $v;
			}
			elseif($v['infotype']=='3')//下载类型
			{
				$download_tem[] = $v;
			}
			elseif($v['infotype']=='4')//商品类型
			{
				$goods_tem[] = $v;
			}
			else
			{

			}
		}

		if(!empty($page_tem))
		{
			foreach ($page_tem as $v)
			{
				create_page_action($v['id'],$v['classname'],$v['seotitle'],$v['keywords'],$v['description'],$v['tpl'],$v['htmlname'],$lang);
			}
		}
		if(!empty($article_tem))
		{
			foreach ($article_tem as $v)
			{
				create_article_action($v['id'],$v['classname'],$v['seotitle'],$v['keywords'],$v['description'],$v['tpl'],$v['htmlname'],$lang);
			}
		}
		if(!empty($imginfo_tem))
		{
			foreach ($imginfo_tem as $v)
			{
				create_imginfo_action($v['id'],$v['classname'],$v['seotitle'],$v['keywords'],$v['description'],$v['tpl'],$v['htmlname'],$lang);
			}
		}
		if(!empty($download_tem))
		{
			foreach ($download_tem as $v)
			{
				create_download_action($v['id'],$v['classname'],$v['seotitle'],$v['keywords'],$v['description'],$v['tpl'],$v['htmlname'],$lang);
			}
		}
	}
	$data['all_class'] = count($all_class);
	return $data;
}
/**
 * 生成单页处理函数
 * @param int $id  栏目ID
 * @param sting $classname 栏目名称
 * @param string $seotitle seo标题
 * @param string $keywords seo关键字
 * @param string $description seo描述
 * @param string $tpl 模版名称
 * @param string $htmlname 静态文件名
 * @param string $lang 语言
 * @param int $pid 栏目PID
 */
function create_page_action($id,$classname,$seotitle,$keywords,$description,$tpl,$htmlname,$lang)
{
	global $smarty;
	//================公共赋值区域==============================================
	common_assign($lang);
	$info_data = SysInfo($id,0,'',$lang);
	$smarty->assign("content",$info_data['content']);//文章内容
	$smarty->assign("posstr",SysGetPosStr($id,0,'&nbsp;&gt;&nbsp;',$lang));//当前位置
	$smarty->assign("catname",GetCatName($id));//栏目名称
	$smarty->assign("is_message",$info_data['is_message']);//是否留言
	$smarty->assign("meta_data",SysGetHeader(1,$id,0,'',$lang));//header信息
	$html_file = get_file_name($id,$htmlname,$lang,0,FALSE);
	$fp = fopen(PHPMYWIND_ROOT.'/'.$html_file, "w");
	$content = $smarty->fetch($tpl);
	fwrite($fp, $content);
	fclose($fp);
}
/**
 * 生成文章处理函数
 * @param int $id  栏目ID
 * @param sting $classname 栏目名称
 * @param string $seotitle seo标题
 * @param string $keywords seo关键字
 * @param string $description seo描述
 * @param string $tpl 模版名称
 * @param string $htmlname 静态文件名
 * @param string $lang 语言
 * @param int $pid 栏目PID
 */
function create_article_action($id,$classname,$seotitle,$keywords,$description,$tpl,$htmlname,$lang)
{
	global $smarty,$dosql,$dopage;
	//================公共赋值区域==============================================
	common_assign($lang);
	$smarty->assign("htmlname",$htmlname);
	$smarty->assign("posstr",SysGetPosStr($id,0,'&nbsp;&gt;&nbsp;',$lang));//当前位置
	$smarty->assign("catname",GetCatName($id));//栏目名称
	$smarty->assign("meta_data",SysGetHeader(1,$id,0,'',$lang));//header信息

	$cid = empty($id) ? 4 : intval($id);//栏目ID
	$limit = 15;//每页分页数
	//===========================获取记录总数sqlstart=============================
	$count_sql = "SELECT COUNT(*) AS data_count FROM `#@__infolist`";
	$count_sql .= " WHERE (classid=$cid OR parentstr LIKE '%,$cid,%')";
	$count_sql .= " AND delstate='' AND checkinfo=true AND lang='$lang'";
	//===========================获取记录总数sqlend===============================

	//===========================获取数据sqlstart=============================
	$sql = "SELECT n.*,c.classname";
	$sql .= " FROM `#@__infolist` AS n";
	$sql .= " LEFT JOIN `#@__infoclass` AS c ON  c.id=n.classid";
	$sql .= " WHERE (n.classid=$cid OR n.parentstr LIKE '%,$cid,%')";
	$sql .= " AND n.delstate='' AND n.checkinfo=true AND n.lang='$lang'";
	$sql .= " ORDER BY n.orderid DESC";
	//===========================获取数据sqlend===============================

	$rs = $dosql->GetOne($count_sql);
	$data_count = $rs['data_count'];

	$excu_count = ceil($data_count / $limit);

	for($page = 1; $page <= $excu_count; $page++){

		$offset = ($page - 1) * $limit;
		$dopage->SysGetPage($sql,$limit,$offset);
		$html_file = get_file_name($id,$htmlname,$lang,1,$page);
		$list_data = get_page_list($data_count,substr($html_file, 0,strrpos($html_file, '-')),$page,$limit,$lang);
		$smarty->assign("pages",$list_data['page']);
		$smarty->assign("datas",$list_data['data']);
		create_content($htmlname,$id,$list_data['data'],$lang,1);//生成内容页
		$fp = fopen(PHPMYWIND_ROOT.'/'.$html_file, "w");
		$content = $smarty->fetch($tpl);
		fwrite($fp, $content);
		fclose($fp);
	}
}
/**
 * 生成图片模型处理函数
 * @param int $id  栏目ID
 * @param sting $classname 栏目名称
 * @param string $seotitle seo标题
 * @param string $keywords seo关键字
 * @param string $description seo描述
 * @param string $tpl 模版名称
 * @param string $htmlname 静态文件名
 * @param string $lang 语言
 * @param int $pid 栏目PID
 */
function create_imginfo_action($id,$classname,$seotitle,$keywords,$description,$tpl,$htmlname,$lang)
{
	global $smarty,$dosql,$dopage;
	//================公共赋值区域==============================================
	common_assign($lang);
	$smarty->assign("htmlname",$htmlname);
	$smarty->assign("posstr",SysGetPosStr($id,0,'&nbsp;&gt;&nbsp;',$lang));//当前位置
	$smarty->assign("catname",GetCatName($id));//栏目名称
	$smarty->assign("meta_data",SysGetHeader(1,$id,0,'',$lang));//header信息

	$cid = empty($id) ? 4 : intval($id);//栏目ID
	$limit = 2;//每页分页数
	//===========================获取记录总数sqlstart=============================
	$count_sql = "SELECT COUNT(*) AS data_count FROM `#@__infoimg`";
	$count_sql .= " WHERE (classid=$cid OR parentstr LIKE '%,$cid,%')";
	$count_sql .= " AND delstate='' AND checkinfo=true AND lang='$lang'";
	//===========================获取记录总数sqlend===============================

	//===========================获取数据sqlstart=============================
	$sql = "SELECT n.*,c.classname";
	$sql .= " FROM `#@__infoimg` AS n";
	$sql .= " LEFT JOIN `#@__infoclass` AS c ON  c.id=n.classid";
	$sql .= " WHERE (n.classid=$cid OR n.parentstr LIKE '%,$cid,%')";
	$sql .= " AND n.delstate='' AND n.checkinfo=true AND n.lang='$lang'";
	$sql .= " ORDER BY n.orderid DESC";
	//===========================获取数据sqlend===============================

	$rs = $dosql->GetOne($count_sql);
	$data_count = $rs['data_count'];

	$excu_count = ceil($data_count / $limit);

	for($page = 1; $page <= $excu_count; $page++){

		$offset = ($page - 1) * $limit;
		$dopage->SysGetPage($sql,$limit,$offset);
		$html_file = get_file_name($id,$htmlname,$lang,2,$page);
		$list_data = get_page_list($data_count,substr($html_file, 0,strrpos($html_file, '-')),$page,$limit,$lang);
		$smarty->assign("pages",$list_data['page']);
		$smarty->assign("datas",$list_data['data']);
		create_content($htmlname,$id,$list_data['data'],$lang,2);//生成内容页
		$fp = fopen(PHPMYWIND_ROOT.'/'.$html_file, "w");
		$content = $smarty->fetch($tpl);
		fwrite($fp, $content);
		fclose($fp);
	}
}
/**
 * 生成下载模型处理函数
 * @param int $id  栏目ID
 * @param sting $classname 栏目名称
 * @param string $seotitle seo标题
 * @param string $keywords seo关键字
 * @param string $description seo描述
 * @param string $tpl 模版名称
 * @param string $htmlname 静态文件名
 * @param string $lang 语言
 * @param int $pid 栏目PID
 */
function create_download_action($id,$classname,$seotitle,$keywords,$description,$tpl,$htmlname,$lang)
{
	global $smarty,$dosql,$dopage;
	//================公共赋值区域==============================================
	common_assign($lang);
	$smarty->assign("htmlname",$htmlname);
	$smarty->assign("posstr",SysGetPosStr($id,0,'&nbsp;&gt;&nbsp;',$lang));//当前位置
	$smarty->assign("catname",GetCatName($id));//栏目名称
	$smarty->assign("meta_data",SysGetHeader(1,$id,0,'',$lang));//header信息

	$cid = empty($id) ? 4 : intval($id);//栏目ID
	$limit = 2;//每页分页数
	//===========================获取记录总数sqlstart=============================
	$count_sql = "SELECT COUNT(*) AS data_count FROM `#@__soft`";
	$count_sql .= " WHERE (classid=$cid OR parentstr LIKE '%,$cid,%')";
	$count_sql .= " AND delstate='' AND checkinfo=true AND lang='$lang'";
	//===========================获取记录总数sqlend===============================

	//===========================获取数据sqlstart=============================
	$sql = "SELECT n.*,c.classname";
	$sql .= " FROM `#@__soft` AS n";
	$sql .= " LEFT JOIN `#@__infoclass` AS c ON  c.id=n.classid";
	$sql .= " WHERE (n.classid=$cid OR n.parentstr LIKE '%,$cid,%')";
	$sql .= " AND n.delstate='' AND n.checkinfo=true AND n.lang='$lang'";
	$sql .= " ORDER BY n.orderid DESC";
	//===========================获取数据sqlend===============================

	$rs = $dosql->GetOne($count_sql);
	$data_count = $rs['data_count'];

	$excu_count = ceil($data_count / $limit);

	for($page = 1; $page <= $excu_count; $page++){

		$offset = ($page - 1) * $limit;
		$dopage->SysGetPage($sql,$limit,$offset);
		$html_file = get_file_name($id,$htmlname,$lang,3,$page);
		$list_data = get_page_list($data_count,substr($html_file, 0,strrpos($html_file, '-')),$page,$limit,$lang);
		$smarty->assign("pages",$list_data['page']);
		$smarty->assign("datas",$list_data['data']);
		create_content($htmlname,$id,$list_data['data'],$lang,3);//生成内容页
		$fp = fopen(PHPMYWIND_ROOT.'/'.$html_file, "w");
		$content = $smarty->fetch($tpl);
		fwrite($fp, $content);
		fclose($fp);
	}
}
/**
 * 创建内容页
 * @param string $htmlname 文件别名
 * @param int $cid 栏目ID
 * @param int $data 数据
 * @param string $lang 语言
 * @param int $ctype 栏目类型
 */
function create_content($htmlname,$cid,$data,$lang,$ctype)
{
	global $smarty,$htm_ext;
	if(!empty($data))
	{
		$smarty->assign("catname",GetCatName($cid));//栏目名称
		foreach ($data as $v)
		{
			$smarty->assign("posstr",SysGetPosStr($cid,$v['id'],'&nbsp;&gt;&nbsp;',$lang));//当前位置
			$smarty->assign("meta_data",SysGetHeader(1,$cid,$v['id'],'',$lang));//header信息
			$smarty->assign("rs",$v);
			$smarty->assign("pre_next",get_pre_next($htmlname,$cid,$v['id'],$v['orderid'],$lang,$ctype));
			$fp = fopen(PHPMYWIND_ROOT.'/'.$htmlname.'-show-'.$v['id'].$htm_ext, "w");
			$content = $smarty->fetch($htmlname.'_show.tpl');
			fwrite($fp, $content);
			fclose($fp);
		}
	}
}
/**
 * 获取数据上一页 下一页
 * @param string $htmlname html别名
 * @param int $cid 栏目ID
 * @param int $id 当前数据ID
 * @param int $orderid 排序号
 * @param string $lang 语言
 * @param int $ctype 栏目类型
 * @return Ambigous <multitype:, string, unknown>
 */
function get_pre_next($htmlname,$cid,$id,$orderid,$lang,$ctype)
{
	global $dosql,$htm_ext;
	$data = array();
	switch ($ctype)
	{
		case 1:
			$table_name = '#@__infolist';
			break;
		case 2:
			$table_name = '#@__infoimg';
			break;
		case 3:
			$table_name = '#@__soft';
			break;
		case 4:
			$table_name = '#@__goods';
			break;
	}
	//获取上一篇信息
	$r = $dosql->GetOne("SELECT * FROM `$table_name` WHERE classid=".$cid." AND id<".$id." AND delstate='' AND checkinfo=true ORDER BY orderid DESC");
	if($r < 1)
	{
		$data['pre'] = L('no_data',$lang);
	}
	else
	{
		$gourl = $htmlname.'-show-'.$r['id'].$htm_ext;
		$data['pre'] = '<a href="'.$gourl.'">'.$r['title'].'</a>';
	}

	//获取下一篇信息
	$r = $dosql->GetOne("SELECT * FROM `$table_name` WHERE classid=".$cid." AND id>".$id." AND delstate='' AND checkinfo=true ORDER BY orderid ASC");
	if($r < 1)
	{
		$data['next'] = L('no_data',$lang);
	}
	else
	{
		$gourl = $htmlname.'-show-'.$r['id'].$htm_ext;
		$data['next'] = '<a href="'.$gourl.'">'.$r['title'].'</a>';
	}
	return $data;
}
/**
 * 获取生成文件名
 * @param string $htmlname 文件别名
 * @param string $lang 语言
 * @param int $class_type 栏目类型
 * @param int $page 页码数
 * @return string
 */
function get_file_name($class_id,$htmlname,$lang,$class_type=0,$page=FALSE)
{
	global $is_htmldir,$default_htmldir,$htm_ext;
	$all_type_html = array('0'=>'page','1'=>'article','2'=>'infoimg','3'=>'download','4'=>'goods');
	if($class_type==0 && $htmlname!=$all_type_html[$class_type])
	{
		$htmlname = ($is_htmldir=='N')?$htmlname:$default_htmldir.'/'.$htmlname;
	}
	else
	{
		$htmlname = ($is_htmldir=='N')?$htmlname.'-'.$class_id:$default_htmldir.'/'.$htmlname.'-'.$class_id;
	}
	return ($page)?$htmlname.'-'.$page.$htm_ext:$htmlname.$htm_ext;
}

/**
 * 获取所有栏目
 * @param string $lang 语言
 * @return data
 */
function get_all_infoclass($lang)
{
	global $dosql,$cfg_siteid;
	$sql = "SELECT * FROM `#@__infoclass` WHERE siteid='$cfg_siteid' AND lang='$lang' AND checkinfo=true";
	$dosql->Execute($sql);
	return $dosql->getall();
}
/**
 * 生成静态页公共数据
 * @param string $lang  语言
 */
function common_assign($lang)
{
	global $smarty;
	($lang=='en')	?
	require(PHPMYWIND_INC.'/config.en_cache.php') :
	require(PHPMYWIND_INC.'/config.cache.php'); //加载英文配置文件
	$smarty->assign("lang",$lang);//申明模版解析语言变量 notic 每个处理函数都要加上这句
	$smarty->assign("cfg_copyright",$cfg_copyright);//版权
	$smarty->assign("cfg_icp",$cfg_icp);//备案号
	$smarty->assign("cfg_countcode",$cfg_countcode);//统计代码

	$smarty->assign("link_data",get_flink($lang));//友情连接
	$smarty->assign("nav_data",SysGetSubNav(1,$lang));//导航
	$header_content = $smarty->fetch('header.tpl');
	sys_create_file('data', $lang.'_nav.php', $header_content);
	
}
/**
 * 生成静态首页处理函数
 * @param string $lang 语言
 */
function create_index($lang='cn')
{
	global $smarty,$is_htmldir,$default_htmldir,$htm_ext;
	//================公共赋值区域==============================================
	common_assign($lang);

	//================函数赋值区域==============================================
	$smarty->assign("meta_data",SysGetHeader());//首页meta信息
	if($lang=='cn')
	{
		$smarty->assign("index_banner",GetIndexBanner(13,5,$lang));//首页中文banner
		$smarty->assign("pro_data",get_imginfo(5,$lang,15));//推荐产品调用
		$info_data = SysInfo(3,147,'about.html',$lang);
		$smarty->assign("rs_about",$info_data['content']);//关于我们
		$smarty->assign("rs_about_img",InfoPic(3));//关于我们缩略图
		$smarty->assign("rs_news",SysGetFlag(1,4,'h',$lang));//头条新闻
		$smarty->assign("news_data",SysGetData(1,4,$lang,3));//新闻三条
	}
	else
	{
		$smarty->assign("index_banner",GetIndexBanner(26,5,$lang));//首页英文banner
		$smarty->assign("pro_data",get_imginfo(19,$lang,15));//推荐产品调用
		$info_data = SysInfo(15,147,'about-en.html',$lang);
		$smarty->assign("rs_about",$info_data['content']);//关于我们
		$smarty->assign("rs_about_img",InfoPic(15));//关于我们缩略图
		$smarty->assign("rs_news",SysGetFlag(1,18,'h',$lang));//头条新闻
		$smarty->assign("news_data",SysGetData(1,18,$lang,3));//新闻三条
	}
	if($lang==$default_htmldir)
	{
		if($is_htmldir == 'Y')//判断启用英文目录
		{
			$fp = fopen(PHPMYWIND_ROOT.'/'.$default_htmldir.'/index'.$htm_ext, "w");
		}
		else
		{
			$fp = fopen(PHPMYWIND_ROOT.'/index-'.$default_htmldir.$htm_ext, "w");
		}
	}
	else
	{
		$fp = fopen(PHPMYWIND_ROOT.'/index.html', "w");
	}
	$content = $smarty->fetch("index.tpl");
	fwrite($fp, $content);
	fclose($fp);
}
/**
 * 获取分页信息
 * @param int $data_count 总条数
 * @param string $parameter url
 * @param int $page 当前页
 * @param int $limit 分页数
 * @param string $lang 语言
 * @return Ambigous <multitype:, unknown>
 */
function get_page_list($data_count,$parameter,$page,$limit,$lang){

	global $dosql,$dopage;
	$data = array();
	$params = array(
			'total_rows'=>$data_count, #(必须)
			'method'    =>'html', #(必须)
			'parameter' =>$parameter,  #(必须)
			'now_page'  =>$page,  #(必须)
			'list_rows' =>$limit, #(可选) 默认为15
			'lang' 		=>$lang
	);
	$page = new Sys_page($params);
	$data['page'] = $page->show(2);
	$data['data'] = $dosql->getall();
	return $data;
}
/**
 * 获取友情链接函数
 * @param string $lang 语言
 * @return Ambigous <multitype:, unknown>
 */
function get_flink($lang)
{
	global $dosql;
	$sql = "SELECT * FROM `#@__weblink`";
	$sql .= " WHERE checkinfo=true AND lang='$lang'";
	$sql .= " ORDER BY orderid,id DESC";
	$dosql->Execute($sql);
	return $dosql->getall();
}
/**
 * 获取图片栏目信息
 * @param int $classid 栏目ID
 * @param string $lang 语言
 * @param int $limit 条数
 * @return Ambigous <multitype:, string, boolean>
 */
function get_imginfo($classid,$lang,$limit=20)
{
	global $dosql;
	$data = array();
	$dosql->Execute("SELECT * FROM `#@__infoimg`
	 WHERE (classid=$classid OR parentstr LIKE '%,$classid,%') 
	 AND delstate='' AND checkinfo=true AND lang='$lang' 
	 ORDER BY orderid DESC LIMIT 0,$limit");
	$i=0;
	while($row = $dosql->GetArray())
	{
		//获取链接地址
		$gourl = $row['linkurl']!='' ?
		$row['linkurl'] :
		'productshow-'.$row['classid'].'-'.$row['id'].'.html';
		//获取缩略图地址
		if($row['picurl']!='')
		$picurl = $row['picurl'];
		else
		$picurl = 'templates/default/images/nofoundpic.gif';

		$data[$i] =  $row;
		$data[$i]['picurl'] = $picurl;
		$data[$i]['gourl'] = $gourl;
		$i++;
	}
	return $data;
}
/**
 * 获取网站导航数据
 * @param int $id 父ID
 * @param string $lang 语言
 * @return Ambigous <multitype:, string>
 */
function SysGetSubNav($id,$lang)
{
	global $dosql, $cfg_isreurl,$default_htmldir,$htm_ext,$is_htmldir;

	$all_type_html = array('0'=>'page','1'=>'article','2'=>'infoimg','3'=>'download','4'=>'goods');

	$tem_arr = array();
	$row = $dosql->Execute("SELECT * FROM `#@__nav` WHERE parentid=$id AND checkinfo=true  ORDER BY orderid ASC", $id);
	$i=0;
	while($row = $dosql->GetArray($id))
	{

		if($lang=='en')
		{
			if($row['encid']>0)
			{
				$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` WHERE `id`=".$row['encid']);
				$class_id = $row['encid'];
			}
			else
			{
				$htmlname = ($is_htmldir=='Y')?'index'.$htm_ext:'index-en'.$htm_ext;
			}
		}
		else
		{
			if($row['encid']>0)
			{
				$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` WHERE `id`=".$row['cncid']);
				$class_id = $row['cncid'];
			}
			else
			{
				$htmlname = 'index'.$htm_ext;
			}
		}
		if(isset($r))
		{
			if($r['infotype']==0 && $r['htmlname']!=$all_type_html[0])
			{
				$htmlname = $r['htmlname'].$htm_ext;
			}
			elseif($r['infotype']==0 && $r['htmlname']==$all_type_html[0])
			{
					
				$htmlname = $r['htmlname'].'-'.$class_id.$htm_ext;
			}
			else
			{
				$htmlname = $r['htmlname'].'-'.$class_id.'-1'.$htm_ext;
			}
		}
		$tem_arr[$i] = $row;
		$tem_arr[$i]['classname'] = $lang=='en'?$row['enclassname']:$row['classname'];
		$tem_arr[$i]['html_url'] = $htmlname;
		$row2 = $dosql->Execute("SELECT * FROM `#@__nav` WHERE parentid=".$row["id"]." AND checkinfo=true ORDER BY orderid DESC", $row['id']);
		if($dosql->GetTotalRow($row['id']))
		{
			$tem_arr[$i]['son'] = SysGetSubNav($row["id"],$lang);
		}
		else
		{
			$tem_arr[$i]['son'] = array();
		}
		$i++;
	}
	return $tem_arr;
}

/**
 * 获取页面头部信息
 * @param int $sid 站点id
 * @param int $cid 栏目ID
 * @param int $id 内容ID 非则为0
 * @param string $str 自定义标题
 * @param string $lang 语言
 * @return string
 */
function SysGetHeader($sid=1,$cid=0,$id=0,$str='',$lang='cn')
{
	global $dosql;
	($lang=='en')	?
	require(PHPMYWIND_INC.'/config.en_cache.php') :
	require(PHPMYWIND_INC.'/config.cache.php'); //加载英文配置文件
	//检查站点标识
	if($sid != 1)
	{
		$r = $dosql->GetOne("SELECT `sitekey` FROM `#@__site` WHERE `id`=$sid");
		if(isset($r['sitekey']))
		{
			$cfg_webname     = $GLOBALS['cfg_webname_'.$r['sitekey']];
			$cfg_generator   = $GLOBALS['cfg_generator_'.$r['sitekey']];
			$cfg_author      = $GLOBALS['cfg_author_'.$r['sitekey']];
			$cfg_keyword     = $GLOBALS['cfg_keyword_'.$r['sitekey']];
			$cfg_description = $GLOBALS['cfg_description_'.$r['sitekey']];
		}
	}



	//设置了自定义标题
	if($str != '')
	{
		$header_str  = '<title>'.$str.' - '.$cfg_webname.'</title>'."\n";
		$header_str .= '<meta name="generator" content="'.$cfg_generator.'" />'."\n";
		$header_str .= '<meta name="author" content="'.$cfg_author.'" />'."\n";
		$header_str .= '<meta name="keywords" content="'.$cfg_keyword.'" />'."\n";
		$header_str .= '<meta name="description" content="'.$cfg_description.'" />'."\n";
	}


	else
	{
		//显示详细信息
		if(!empty($cid) && !empty($id))
		{
			$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` WHERE `id`=$cid");

			if(isset($r['infotype']))
			{
				if($r['infotype'] == 1)
				$tbname = '#@__infolist';

				else if($r['infotype'] == 2)
				$tbname = '#@__infoimg';

				else if($r['infotype'] == 3)
				$tbname = '#@__soft';

				else if($r['infotype'] == 4)
				$tbname = '#@__goods';


				//获取栏目信息
				$r2 = $dosql->GetOne("SELECT * FROM `$tbname` WHERE `id`=$id");
					
				$header_str = '<title>';
					
				if(isset($r2['title']))
				$header_str .= $r2['title'].' - ';
					
				if(isset($r['classname']))
				$header_str .= $r['classname'];
					
				$header_str .= ' - '.$cfg_webname.'</title>'."\n";
				$header_str .= '<meta name="generator" content="'.$cfg_generator.'" />'."\n";
				$header_str .= '<meta name="author" content="'.$cfg_author.'" />'."\n";
				$header_str .= '<meta name="keywords" content="';

				if(isset($r2['keywords']))
				$header_str .= $r2['keywords'];
				else
				$header_str .= $cfg_keyword;
					
				$header_str .= '" />'."\n";
				$header_str .= '<meta name="description" content="';

				if(isset($r2['description']))
				$header_str .= $r2['description'];
				else
				$header_str .= $cfg_description;
					
				$header_str .= '" />'."\n";
			}
			else
			{
				return '';
			}
		}

		//显示栏目信息
		else if(!empty($cid))
		{
			$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` WHERE `id`=$cid");

			$header_str = '<title>';

			if(!empty($r['seotitle']))
			$header_str .= $r['seotitle'];
			else if(!empty($r['classname']))
			$header_str .= $r['classname'].' - '.$cfg_webname;
			else
			$header_str .= $cfg_webname;

			$header_str .= '</title>'."\n";
			$header_str .= '<meta name="generator" content="'.$cfg_generator.'" />'."\n";
			$header_str .= '<meta name="author" content="'.$cfg_author.'" />'."\n";
			$header_str .= '<meta name="keywords" content="';

			if(!empty($r['keywords']))
			$header_str .= $r['keywords'];
			else
			$header_str .= $cfg_keyword;

			$header_str .= '" />'."\n";
			$header_str .= '<meta name="description" content="';

			if(!empty($r['description']))
			$header_str .= $r['description'];
			else
			$header_str .= $cfg_description;

			$header_str .= '" />'."\n";
		}

		//显示站点信息
		else
		{
			$header_str  = '<title>'.$cfg_webname.'</title>'."\n";
			$header_str .= '<meta name="generator" content="'.$cfg_generator.'" />'."\n";
			$header_str .= '<meta name="author" content="'.$cfg_author.'" />'."\n";
			$header_str .= '<meta name="keywords" content="'.$cfg_keyword.'" />'."\n";
			$header_str .= '<meta name="description" content="'.$cfg_description.'" />'."\n";
		}
	}

	return $header_str;
}
/**
 * 获取单页信息
 * @param int $cid 栏目ID
 * @param int $num 显示的字符数 0则不限制
 * @param string $gourl 是否加更多链接
 * @param string $lang 语言
 * @return Ambigous <boolean, string>|Ambigous <string, unknown>
 */
function SysInfo($cid=0, $num=0, $gourl='',$lang='cn')
{
	global $dosql;
	$contstr = '';

	$row = $dosql->GetOne("SELECT * FROM `#@__info` WHERE classid=$cid AND lang='$lang'");
	if(isset($row['content']))
	{
		if(!empty($num))
		{
			$contstr .= ReStrLen($row['content'], $num);
		}
		else
		{
			$data['content'] = $row['content'];
			$data['is_message'] = $row['is_message'];
			return $data;
			
		}
		if($gourl != '') $contstr .= ' <a href="'.$gourl.'">['.L('more',$lang).'>>]</a>';
	}
	else
	{
		$contstr .= L('content_updateing',$lang);
	}

	$data['content'] = $contstr;
	$data['is_message'] = $row['is_message'];
	return $data;
}
/**
 * 获取页面位置
 * @param int $cid 栏目ID
 * @param int $id 内容ID 无则为0
 * @param string $sign 间隔符号
 * @param string $lang 语言
 * @return string
 */
function SysGetPosStr($cid=0,$id=0,$sign='&nbsp;&gt;&nbsp;',$lang='cn')
{
	global $dosql,$cfg_webpath,$default_htmldir,$is_htmldir,$htm_ext;


	//设置首页链接
	if($is_htmldir=='Y' && $lang==$default_htmldir)
	$pos_str = '<a href="'.$cfg_webpath.'/'.$default_htmldir.'">'.L('home_page',$lang).'</a>';
	elseif($is_htmldir=='N' && $lang==$default_htmldir)
	$pos_str = '<a href="'.$cfg_webpath.'/index-'.$default_htmldir.$htm_ext.'">'.L('home_page',$lang).'</a>';
	else
	$pos_str = '<a href="'.$cfg_webpath.'">'.L('home_page',$lang).'</a>';


	//如果cid为空，获取串，否则视为首页
	if(!empty($cid))
	{

		//获取当前栏目信息
		$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` where `id`=$cid");
		if(empty($r['parentstr']))
		{
			return $pos_str.$sign.'栏目不存在';
		}
		else
		{
			//构成上级栏目字符
			if($r['parentstr'] != '0,')
			{
				$pid_arr = explode(',', $r['parentstr']);

				foreach($pid_arr as $v)
				{
					if(!empty($v))
					{
						$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` where `id`=$v");
						$pos_str .= $sign.$r['classname'];
					}
				}
			}

			//构成本级栏目字符
			$r = $dosql->GetOne("SELECT * FROM `#@__infoclass` WHERE `id`=$cid");
			if(isset($r) && is_array($r))
			{
				if(!empty($id))
				if($lang=='cn')
				return $pos_str.$sign.$r['classname'].$sign.'正文';
				else
				return $pos_str.$sign.$r['classname'].$sign.'content';
				else
				return $pos_str.$sign.$r['classname'];
			}
			else
			{
				return $pos_str.$sign.'栏目不存在';
			}
		}
	}
	else
	{
		return $pos_str;
	}
}
/**
 * 根据栏目属性  推荐 头条等获取数据一条数据
 * @param int $ctype 栏目类型 
 * @param int $cid 栏目ID
 * @param string $flag 栏目属性
 * @param string $lang 语言
 * @return Ambigous <boolean, string>
 */
function SysGetFlag($ctype,$cid,$flag,$lang)
{
	global $dosql;
	switch ($ctype)
	{
		case 1:
			$table_name = '#@__infolist';
			break;
		case 2:
			$table_name = '#@__infoimg';
			break;
		case 3:
			$table_name = '#@__soft';
			break;
		case 4:
			$table_name = '#@__goods';
			break;
	}
	return $dosql->GetOne("SELECT * FROM `$table_name` WHERE (classid=$cid OR parentstr LIKE '%,$cid,%') AND flag LIKE '%$flag%' AND delstate='' AND checkinfo=true AND lang='$lang' ORDER BY orderid DESC");
}
/**
 * 更具栏目ID 栏目类型 获取指定条数的数据
 * @param int $ctype 栏目类型 
 * @param int $cid 栏目ID
 * @param string $lang 语言
 * @param int $limit 显示条数
 * @return Ambigous <multitype:, unknown>
 */
function SysGetData($ctype,$cid,$lang,$limit=5)
{
	global $dosql;
	switch ($ctype)
	{
		case 1:
			$table_name = '#@__infolist';
			break;
		case 2:
			$table_name = '#@__infoimg';
			break;
		case 3:
			$table_name = '#@__soft';
			break;
		case 4:
			$table_name = '#@__goods';
			break;
	}
	$dosql->Execute("SELECT * FROM `$table_name` WHERE (classid=$cid OR parentstr LIKE '%,$cid,%') AND delstate='' AND checkinfo=true AND lang='$lang' ORDER BY orderid DESC,posttime DESC Limit 0,$limit");
	return $dosql->getall();
}
